package cn.edu.scau.cmi.yangzhengkai.client.classicsDesignPattern;

import cn.edu.scau.cmi.yangzhengkai.abstractFactory.domainAbstractClass.Meat;
import cn.edu.scau.cmi.yangzhengkai.abstractFactory.factory.AbstractFactory;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class AbstractFactoryClient extends Application{

	@Override
	public void start(Stage primaryStage){
		
		FlowPane fp = new FlowPane();
		HBox hb1 = new HBox();
		HBox hb2 = new HBox();
		HBox hb3 = new HBox();
		Text t1 = new Text("Please select which the brands you want to eat:");
		Text t2 = new Text("Please select which kind of meat you want to eat:");
		ComboBox<String> cb1 = new ComboBox<String>();
		ComboBox<String> cb2 = new ComboBox<String>();
		Button bu = new Button("Yes");
		Label lb = new Label();
		
		t1.setStyle("-fx-font-size:18");
		t2.setStyle("-fx-font-size:18");
		cb1.setStyle("-fx-font-size:16");
		cb2.setStyle("-fx-font-size:16");
		lb.setStyle("-fx-font-size:18");
		cb1.getItems().addAll("Wens","Tianbang","Aonong");
		cb2.getItems().addAll("beef","chicken","pork");
		hb1.getChildren().addAll(t1,cb1);
		hb2.getChildren().addAll(t2,cb2,bu);
		hb3.getChildren().add(lb);
		hb1.setMargin(t1,new Insets(10, 0, 0, 20));
		hb1.setMargin(cb1,new Insets(5, 5, 0, 5));
		hb2.setMargin(bu,new Insets(5, 0, 0, 0));
		hb2.setMargin(t2,new Insets(10, 0, 0, 20));
		hb2.setMargin(cb2,new Insets(5, 5, 0, 20));
		hb3.setMargin(lb,new Insets(5, 5, 0, 20));
		fp.setOrientation(Orientation.VERTICAL);
		fp.getChildren().addAll(hb1,hb2,hb3);

		bu.setOnAction(new EventHandler<ActionEvent>() {
			
			@Override
			public void handle(ActionEvent event) {

				String s1 = cb1.getValue();
				String s2 = cb2.getValue();
				AbstractFactory factory = null;
				Meat meat = null;
				switch (s1) {
				case "Wens":
					factory = AbstractFactory.getFactory("Wens");
					break;
				case "Tianbang":
					factory = AbstractFactory.getFactory("Tianbang");
					break;
				case "Aonong":
					factory = AbstractFactory.getFactory("Aonong");
					break;
				}
				
				switch (s2) {
				case "beef":
					meat = factory.createBeef();
					break;
				case "chicken":
					meat = factory.createChicken();
					break;
				case "pork":
					meat = factory.createPork();
					break;
				}
				
				lb.setText(meat.cook());
				
				
			}
		});
		
		
		Scene scene = new Scene(fp);
		primaryStage.setScene(scene);
		primaryStage.setWidth(800);
		primaryStage.setHeight(500);
		primaryStage.show();
	}
	
	

}
